package com.cheng.io.output;

import com.cheng.io.entity.Student;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
 * 序列化自定义类型对象
 * 自定义类必须实现Serializable接口，默认编译器会自动添加一个序列化版本号（serialVersionUID）
 */
public class ObjectOutputStreamTest03 {
    public static void main(String[] args) {
        try (
                ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("io/resources/student"));
        ) {

            Student student = new Student("zhangsan", 22);
            objectOutputStream.writeObject(student);

            objectOutputStream.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
